<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/11 0011
 * Time: 16:15
 */

namespace app\api\controller\v1\cleaner;


use app\api\controller\v1\Cleaner;
use app\currency\service\CitiesService;
use think\Db;

class Address extends Cleaner
{
    protected $table = 'CitiesCleaner';

    /**
     * 绑定地址列表
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function index()
    {
        $list = $this->_query($this->table)->where('cid','eq',$this->cid)->page(true,false,false,10);
        foreach ($list['list'] as &$item) {
            $item['address'] = CitiesService::getAddressText($item['cities_id'],'string','-');
        }
        $this->success('获取绑定地址成功！',$list);
    }
    public function save()
    {
        $data = $this->_input([
            'address' => $this->request->post('address')
        ],[
            'address' => 'require'
        ],[
            'address.require' => '请填写地址'
        ]);
        Db::name('CleanerAddress')->insert([
            'cid' => $this->cid,
            'address' => $data['address']
        ]);
        $this->success('提交成功！');
    }
}